/*
 * MIT License
 *
 * Copyright (c) 2025 Mark·虎
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 */

package com.hsxxherp.key.support.i18n.controller;

import com.hsxxherp.key.support.i18n.model.entity.I18nResourceTemplate;
import com.hsxxherp.key.support.i18n.service.II18nResourceTemplateService;
import com.hsxxherp.key.support.model.entity.ApiBaseResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 资源模板控制器，处理资源模板的注册和查询等操作
 */
@RestController
@RequestMapping("/api/i18n/resource-template")
@Tag(name = "I18nResourceTemplate 管理", description = "多语资源管理")
public class I18nResourceTemplateController {

    @Autowired
    private II18nResourceTemplateService<I18nResourceTemplate> resourceTemplateService;

    /**
     * 注册资源模板
     *
     * @param template 要注册的资源模板对象，通过请求体传递
     * @return 包含注册结果的通用返回结果对象
     */
    @Operation(summary = "注册资源模板", description = "用于注册资源模板")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "注册成功",
                    content = @Content(schema = @Schema(implementation = I18nResourceTemplate.class))),
            @ApiResponse(responseCode = "400", description = "请求参数错误", content = @Content),
            @ApiResponse(responseCode = "500", description = "服务器内部错误", content = @Content)
    })
    @PostMapping("/register")
    public ApiBaseResponse<I18nResourceTemplate> registerResourceTemplate(@RequestBody I18nResourceTemplate template) {
        // 调用服务层的注册方法
        I18nResourceTemplate registeredTemplate = resourceTemplateService.registerResourceTemplate(template);
        // 返回注册成功的结果
        return ApiBaseResponse.success(registeredTemplate);
    }

    /**
     * 获取所有资源模板
     *
     * @return 包含所有资源模板列表的通用返回结果对象
     */
    @GetMapping("/all")
    public ApiBaseResponse<List<I18nResourceTemplate>> getAllResourceTemplates() {
        // 调用服务层的获取所有资源模板的方法
        List<I18nResourceTemplate> templates = resourceTemplateService.getAllResourceTemplates();
        // 返回获取成功的结果
        return ApiBaseResponse.success(templates);
    }
}